//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.ruoyi.web.controller.exam;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.live.exam.service.LiveScoreStandardService;
import com.ruoyi.live.base.domain.LiveScoreStandard;
import com.ruoyi.live.tool.commons.ICommons;
import com.ruoyi.live.tool.utils.Message;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.Nullable;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller("oldLiveScoreStandardController")
@RequestMapping({"/exam"})
public class LiveScoreStandardController extends BaseController {
    private static final Logger log = LoggerFactory.getLogger(LiveScoreStandardController.class);
    @Autowired
    LiveScoreStandardService service;

    public LiveScoreStandardController() {
    }

    @RequestMapping({"/LiveScoreStandardController/index"})
    public String index() {
        return "exam/live_score_standard_list";
    }

    @ResponseBody
    @RequestMapping({"/LiveScoreStandardController/query"})
    @PreAuthorize("@ss.hasAnyRoles('teacher,expert,admin')")
    public TableDataInfo query(LiveScoreStandard entity) {
        this.startPage();
        List<LiveScoreStandard> list = this.service.query(entity);
        return this.getDataTable(list);
    }

    @ResponseBody
    @RequestMapping({"/list"})
    @PreAuthorize("@ss.hasAnyRoles('teacher,expert,admin')")
    public List<LiveScoreStandard> list(Integer type) {
        return this.service.list(type);
    }

    @ResponseBody
    @RequestMapping({"/LiveScoreStandardController/add"})
    @PreAuthorize("@ss.hasAnyRoles('admin')")
    public Message add(LiveScoreStandard entity) {
        try {
            this.service.addLiveScoreStandard(entity);
            return new Message(true, "新增成功");
        } catch (Exception var3) {
            var3.printStackTrace();
            log.error("", var3);
            return new Message(false, "新增失败");
        }
    }

    @ResponseBody
    @RequestMapping({"/LiveScoreStandardController/update"})
    public Message update(LiveScoreStandard entity) {
        try {
            this.updateLiveScoreStandard(entity);
            return new Message(true, "修改成功");
        } catch (Exception var3) {
            var3.printStackTrace();
            log.error("", var3);
            return new Message(false, "修改失败");
        }
    }

    @PreAuthorize("@ss.hasAnyRoles('admin')")
    public void updateLiveScoreStandard(LiveScoreStandard entity) throws Exception {
        if (!ICommons.isNullOrEmpty(entity.getStandardCode())) {
            this.service.updateLiveScoreStandard(entity);
        } else {
            this.service.updateLiveScoreStandardNoCode(entity);
        }

    }

    @ResponseBody
    @RequestMapping({"/LiveScoreStandardController/delete"})
    @PreAuthorize("@ss.hasAnyRoles('teacher,expert,admin')")
    public Message delete(String id) {
        try {
            this.service.deleteLiveScoreStandard(id.split(","));
            return new Message(true, "删除成功");
        } catch (Exception var3) {
            var3.printStackTrace();
            log.error("", var3);
            return new Message(false, "删除失败");
        }
    }

    @RequestMapping({"/LiveScoreStandardController/view"})
    @PreAuthorize("@ss.hasAnyRoles('teacher,expert,admin')")
    public ModelAndView view(Long id, String page, Integer standardType, @Nullable Long parentId) {
        ModelAndView mv = new ModelAndView("/exam/" + page);
        if (id != null) {
            try {
                LiveScoreStandard entity = this.service.getLiveScoreStandard(id);
                mv.addObject("entity", entity);
                mv.addObject("orders", entity.getOrders());
            } catch (Exception var7) {
                return (new ModelAndView("error")).addObject("tip", var7.getMessage());
            }
        } else {
            mv.addObject("orders", this.service.getOrders(standardType, parentId));
        }

        return mv;
    }
}
